package lion.dev.image.format;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;

import com.sun.jimi.core.JimiException;
import com.sun.jimi.core.JimiImageEnumeration;
import com.sun.jimi.core.encoder.png.PNGEncoder;

import lion.dev.image.FileFormatWriter;

public class FileFormatPNG extends FileFormatWriter {

	public FileFormatPNG() {
		super("PNG", "image/png", ".png");
	}

	public boolean shouldOpenFile() {

		return false;
	}

	@Override
	public void writeImage(OutputStream out, BufferedImage image) throws IOException {

		try {
			PNGEncoder encoder = new PNGEncoder();
			encoder.setAlpha(Boolean.TRUE);
			encoder.encodeImages(new JimiImageEnumeration(image), out);
			out.close();
		} catch (JimiException e) {
			throw new IOException(e + ": " + e.getMessage());
		}
	}
}
